//
//  UITitleTextField.swift
//  test-ios
//
//  Created by wyz5204 on 2023/3/13.
//

import UIKit
import RxSwift


class UITitleTextField: UITextField, UITextFieldDelegate {
    
    private var disposeBag = DisposeBag()
    
    override var placeholder: String? {
        didSet{
            if let _placeholder = placeholder {
                self.attributedPlaceholder = NSAttributedString.init(string: _placeholder, attributes: [NSAttributedString.Key.foregroundColor: UIColor.rd_909399, NSAttributedString.Key.font: UIFont.systemFont(ofSize: 15, weight: .regular)])
            }
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.handleSpecialText()
    }
    
    
    private func handleSpecialText() {
        self.rx.text.asDriver(onErrorJustReturn: "").drive(onNext: {[weak self] text in
            guard let self = self else { return }
            self.text = text
            print("handleSpecialText \(String(describing: self.text) ?? "is null")")
        }).disposed(by: self.disposeBag)
    }
    
    @objc public func cancelHandleSpecialText() {
        self.disposeBag = DisposeBag()
    }
    
    
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}
